package com.ae.shield.common.items.shieldFittings.makers;

import com.ae.shield.common.enchantment.shieldSuffix.SuffixList;
import com.ae.shield.common.items.util.DamageSorter;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.energy.IEnergyStorage;

import java.util.List;

public class FieldShield extends ShieldMakerBase {
    public FieldShield() {
        super(new Properties(), new ShieldProperty()
                .recovery(0.15f)
                .cd(32)
                .maxIntensity(24f)
                .close(1.6f)
                .remote(0.4f)
                .magic(0f)
                .other(0f)
                .upperLimit(30f)
                .floorLimit(0f)
                .maxPiles(2)
                .penalty(10f)
                .cost(6));
    }

    @Override
    public void addCtrlInformation(List<ITextComponent> components, ItemStack stack) {
        components.add(new TranslationTextComponent("tooltip.ae.shield.field_shield.tip1").mergeStyle(TextFormatting.GRAY));
        components.add(new TranslationTextComponent("tooltip.ae.shield.field_shield.tip2").mergeStyle(TextFormatting.GRAY));
        components.add(new TranslationTextComponent("tooltip.ae.shield.field_shield.tip3").mergeStyle(TextFormatting.GREEN));
        components.add(new TranslationTextComponent("tooltip.ae.shield.field_shield.tip4").mergeStyle(TextFormatting.BLUE));
        components.add(new TranslationTextComponent("tooltip.ae.shield.field_shield.tip5").mergeStyle(TextFormatting.GOLD));
        components.add(new TranslationTextComponent("tooltip.ae.shield.field_shield.tip6").mergeStyle(TextFormatting.BLUE));
    }

    @Override
    public float onShieldStartWork(LivingEntity livingEntity, ItemStack stack, float amount, DamageSource source, IEnergyStorage energyCap) {
        int level = EnchantmentHelper.getEnchantmentLevel(SuffixList.LEVEL_UP.get(), stack);
        int i = random.nextInt(100);
        switch (DamageSorter.sort(source)) {
            case SHIELD:
                return amount;
            case REMOTE:
                if (i < (10 + level * 10)) {
                    return 0f;
                } else {
                    return amount;
                }
            default:
                if (i < (6 + level)) {
                    return 0f;
                } else {
                    return amount;
                }
        }
    }
}
